//
//  ByCellRegistrationSegment.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/18.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByCellRegistrationSegment.h"

@implementation ByCellRegistrationSegment
{
    UILabel     *_weekDayLabel;
    UILabel     *_dateLabel;
    UIView      *_line;
}

- (void)createViews{
    for (UIView *subview in self.subviews) {
        [subview removeFromSuperview];
    }
    _weekDayLabel = [[UILabel alloc] init];
    [self addSubview:_weekDayLabel];
    [_weekDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(@(15));
        make.right.equalTo(@(0));
        make.height.equalTo(@(20));
    }];
    _weekDayLabel.font = FONT(14);
    _weekDayLabel.adjustsFontSizeToFitWidth = YES;
    _weekDayLabel.textAlignment = NSTextAlignmentCenter;
    
    _dateLabel = [[UILabel alloc] init];
    [self addSubview:_dateLabel];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(_weekDayLabel.mas_bottom).offset(10);
        make.right.equalTo(@(0));
        make.height.equalTo(@(20));
    }];
    _dateLabel.font = FONT(14);
    _dateLabel.textAlignment = NSTextAlignmentCenter;
    
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(0));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(1, 60));
    }];
    _line.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
}

- (void)setDic:(NSDictionary *)dic{
    [self createViews];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MM-dd"];
    NSString *dateString = [dateFormatter stringFromDate:dic[@"date"]];
    _weekDayLabel.text = dic[@"week"];
    _dateLabel.text = dateString;
}

- (void)setSelected:(BOOL)selected{
    _dateLabel.textColor = selected ? BY_THEME_COLOR : [UIColor blackColor];
    _weekDayLabel.textColor = selected ? BY_THEME_COLOR : [UIColor blackColor];
}
@end
